import axios from 'axios'
export default {
  namespaced: true,
  state: {
    token: localStorage.getItem('token') || '',
    userinfo: {}
  },
  getters: {
  },
  mutations: {
    gettoken (state, val) {
      state.token = val
      console.log(state.token)
      localStorage.setItem('token', state.token)
    },
    setUserInfo (state, val) {
      state.userinfo = val
    }
  },
  actions: {
    async getUserInfo (context) {
      const { data: res } = await axios.get('/my/userinfo')
      // console.log(res)
      if (res.code === 0) {
        context.commit('setUserInfo', res.data)
        // console.log(res.data)
      }
    }
  }
}
